package com.example.fw;

import org.openqa.selenium.By;

public class NavigationHelper extends WebDriverHelperBase
{
	public NavigationHelper(ApplicationManager manager)
	{
		super(manager);
	}

	public void mainPage()
	{
		if (!onMainPage())
		{
			driver.findElement(By.linkText("home")).click();
		}
	}

	public void groupsPage()
	{
		if (!onGroupsPage())
		{
			driver.findElement(By.linkText("groups")).click();
		}
	}

	public void printPhonesPage()
	{
		if (!onPrintPhonesPage())
		{
			driver.findElement(By.linkText("print phones")).click();
		}
	}

	private boolean onMainPage()
	{
		return driver.findElements(By.id("maintable")).size() > 0;
	}

	private boolean onGroupsPage()
	{
		if (driver.getCurrentUrl().contains("group.php") &&
				driver.findElements(By.name("new")).size() > 0)
			return true;
		else
			return false;
	}

	private boolean onPrintPhonesPage()
	{
		return driver.getCurrentUrl().contains("view.php?all&print&phones");
	}

}
